package ru.amse.vlassiev.view;

import java.awt.*;
import java.util.*;
import javax.swing.*;

public class Table extends JPanel implements IView {
	
	private final String myName;
	private java.util.List<DataString> myValue;
		
	private class DataString {
		private long myValue;
		private String myCapture;
		
		public DataString(long value, String capture) {
			myValue = value;
			myCapture = capture;
		}
		
		public long getValue() {
			return myValue;
		}
		
		public String getCapture() {
			return myCapture;
		}
	}
	
	public Table(String name) {
		super();
		myName = name;
		myValue = new ArrayList<DataString>();
	}

	public void update(String capture, long value) {
		myValue.add(new DataString(value, capture));
		this.repaint();
	}
	
	public void paint(Graphics g) {
		super.paint(g);
		double step = 20;
		double x = 20;
		double y = 20;
		int entries = (int) (this.getHeight() / step) - 1;
		int size = myValue.size();
		int i = 2;
		for (DataString data : myValue) {
			if (entries + i++ > size) {
				String s = data.getCapture() + " :   ";
				s += data.getValue();
				g.drawChars(s.toCharArray(), 0, s.length(), (int) x, (int) y);
				y += step;
			}
		}
	}

}
